/**
 * 用户体系
 */

 const sequelize = require('../utils/db.js')
 const {getVal, error, success} = require('../utils/index.js')
 const exec      = require('../utils/exec.js')
 module.exports = {
    ...exec,

    /**
     * 登录
     */
    async login(table = 'users', params) {
        let errStr = '失败'
        try {
            const userData = await sequelize.query(`SELECT * FROM ${table} WHERE phone = ${params['phone']}`)
            let userObj    = userData[0][0]
            if (!userObj) {
               errStr = '账号有误'
               throw Error()
            }else {
               if (userObj.password === params.password) {
                   // 此处应是token
                   return success('token token token', '登陆成功')
               }else {
                   errStr = '密码有误'
                   throw Error()
               }
            }

        } catch (err) {
            return error(errStr)
        }
    }
 }